

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutterdouban/pages/home/home.dart';
import 'package:flutterdouban/pages/main/main.dart';
import 'package:flutterdouban/pages/subject/subject_detail.dart';
import 'package:flutterdouban/router/unknown.dart';

class JKRouter {
  static final Map<String, WidgetBuilder> routes = {
    JKMainPage.routeName: (ctx) => JKMainPage(),
    JKHomePage.routeName: (ctx) => JKHomePage(),
    JKSubjectDetailPage.routeName: (ctx) => JKSubjectDetailPage(),
  };

  // 首先展示的界面
  static final String initialRoute = JKMainPage.routeName;

  // 当routes里面找不到的时候，就会到这里根据名字找到对应的页面
  static final RouteFactory generateRoute = (settings) {
    if (settings.name == JKSubjectDetailPage.routeName) {
      return MaterialPageRoute(
          builder: (ctx) {
            return JKSubjectDetailPage();
          }
      );
    }
    return null;
  };
  // 根据路由找不到界面的时候做展示的错误页面
  static final RouteFactory unknownRoute = (settings) {
    return MaterialPageRoute(
        builder: (ctx) {
          return JKUnknownPage();
        }
    );
  };
}